package com.zpark.resp;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @PackageName: com.zpark.resp
 * @ClassName: ResposeServlet01
 * @Description:
 * @author: RZS
 * @date: 2024/12/10  17:34
 */
@WebServlet("/qs2.do")
public class ResponseServlet02 extends HttpServlet {
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		/*
		设置请求缓冲区编码问题，解决请求参数乱码
		 */
		req.setCharacterEncoding("utf-8");

		// 获取请求参数
		System.out.println("请求参数：" + req.getParameter("name"));

		/*
			response常用方法
		 */
		/*
		 设置响应体类型，简介响应中文内容乱码问题
		 */
		resp.setContentType("text/html;charset=utf-8");

		// 响应数据常用方法
		/*
		 * 获取PrintWriter对象
		 */
		PrintWriter writer = resp.getWriter();
		writer.println("<h1>hello world</h1>");
		writer.println("<h1>你好 世界</h1>");

	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

	}
}
